﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Classes.announcers {
    import flash.events.*;
    import Engine.Managers.*;
    import flash.geom.*;
    import flash.utils.*;
    import __AS3__.vec.*;
    import com.greensock.*;
    import scripting.*;
    import Classes.actions.*;
    import Engine.*;
    import Classes.announcers.announcerinteractions.*;

    public class AnnouncerData extends EventDispatcher implements IScriptingContext {

        private var m_announcerId:String;
        private var m_tilePosition:Point;
        private var m_npc:Announcer;
        private var m_layerName:String;
        private var m_npcName:String;
        private var m_guitarPickName:String;
        private var m_validations:Vector.<Script>;
        private var m_isSilent:Boolean;
        private var m_interactions:Dictionary;

        public function AnnouncerData(_arg1:XML){
            var _local3:XML;
            var _local4:XMLList;
            var _local5:XML;
            var _local6:XMLList;
            var _local7:XML;
            var _local8:XMLList;
            var _local9:String;
            var _local10:XML;
            var _local11:String;
            super();
            this.m_announcerId = _arg1.attribute("id").toString();
            this.m_validations = new Vector.<Script>();
            this.m_isSilent = (((_arg1.attribute("silent").length() > 0)) && ((_arg1.attribute("silent").toString() == "true")));
            this.m_tilePosition = new Point();
            this.m_interactions = new Dictionary();
            var _local2:Script = Global.gameSettings.parseScriptTag(_arg1.child("script")[0], this);
            this.attachScript(_local2);
            if (_arg1.hasOwnProperty("npc")){
                _local3 = _arg1.child("npc")[0];
                this.m_npcName = _local3.attribute("name").toString();
                if (_local3.attribute("x").length() > 0){
                    this.m_tilePosition.x = parseInt(_local3.attribute("x").toString());
                };
                if (_local3.attribute("y").length() > 0){
                    this.m_tilePosition.y = parseInt(_local3.attribute("y").toString());
                };
                this.m_layerName = ((_local3.attribute("layer").length() > 0)) ? _arg1.child("npc").attribute("layer").toString() : "npc";
                if (_local3.hasOwnProperty("guitarPick")){
                    this.m_guitarPickName = _local3.child("guitarPick").attribute("name").toString();
                };
                if (_local3.hasOwnProperty("actions")){
                    _local4 = _local3.child("actions").child("action");
                    for each (_local5 in _local4) {
                    };
                };
            };
            if (((!(this.m_isSilent)) && (_arg1.hasOwnProperty("interactions")))){
                _local6 = _arg1.child("interactions").child("interaction");
                for each (var _local14 in _local6) {
                    _local7 = _local14;
                    _local14;
                    _local8 = _local7.children();
                    _local9 = _local7.attribute("type").toString();
                    if (_local9){
                        for each (var _local16 in _local8) {
                            _local10 = _local16;
                            _local16;
                            _local11 = _local10.name().localName;
                            switch (_local11){
                                case "dialog":
                                    (this.m_interactions[_local9] = new AnnouncerInteractionDialog(this, _local10));
                                    break;
                                case "speech":
                                    (this.m_interactions[_local9] = new AnnouncerInteractionSpeechBubble(this, _local10));
                                    break;
                            };
                        };
                    };
                };
            };
        }
        public function get announcerId():String{
            return (this.m_announcerId);
        }
        public function get npc():Announcer{
            return (this.m_npc);
        }
        public function showAnnouncerNPC(_arg1:Boolean=false):void{
            (this.m_npc = new Announcer(this.m_npcName, false));
            (this.m_npc.customlayerName = this.m_layerName);
            this.m_npc.setOuter(Global.world);
            this.m_npc.setDirection(Constants.DIRECTION_SW);
            this.m_npc.setPosition(this.m_tilePosition.x, this.m_tilePosition.y);
            this.m_npc.getStateMachine().addActions(new NPCAction(this.m_npc));
            this.m_npc.attach();
            if (this.m_guitarPickName){
                this.m_npc.forceUpdateArrowWithCustomIcon(this.m_guitarPickName);
            };
            if (!this.m_isSilent){
                (this.m_npc.playActionCallback = this.onNPCClick);
            };
            if (_arg1){
                (this.m_npc.alpha = 0);
                TweenLite.to(this.m_npc, 1, {alpha:1});
            };
        }
        public function hideAnnouncerNPC(_arg1:Boolean=false):void{
            if (_arg1){
                if (this.m_npc){
                    TweenLite.to(this.m_npc, 1, {
                        alpha:0,
                        onComplete:this.cleanUp
                    });
                };
            } else {
                this.cleanUp();
            };
        }
        protected function cleanUp():void{
            if (this.m_npc){
                this.m_npc.clearStates();
                this.m_npc.detach();
                (this.m_npc.playActionCallback = null);
                (this.m_npc = null);
            };
        }
        public function activateInteraction(_arg1:String):void{
            if (this.m_interactions[_arg1]){
                (this.m_interactions[_arg1] as IAnnouncerInteraction).activate();
                StatsManager.count("announcer", this.m_announcerId, _arg1, this.m_npcName);
            };
        }
        private function onNPCClick():void{
            this.activateInteraction(AnnouncerInteractionTypes.CLICK);
        }
        public function attachScript(_arg1:Script):void{
            this.m_validations.push(_arg1);
        }
        public function validate():Boolean{
            var _local1:Script;
            for each (var _local4 in this.m_validations) {
                _local1 = _local4;
                _local4;
                if (!_local1.validates()){
                    return (false);
                };
            };
            return (true);
        }
        public function onValidate():void{
        }

    }
}//package Classes.announcers 
